﻿using MediatR;
using MS.Common.Infr.Im;
using MS.Common.Infr.In;
using MS.Common.Service;

namespace MS.Basic.ReadAPI.Application.Commons.YangZhiRead
{
    /// <summary>
    /// 养殖信息查询请求处理器
    /// </summary>
    public class YangZhiQueryRequestHandler:IRequestHandler<YangZhiQueryRequestModel,APIResult>
    {
        private readonly IYangZhiRepository yangzhirepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="yangzhirepository"> </param>
        public YangZhiQueryRequestHandler(IYangZhiRepository yangzhirepository)
        {
            this.yangzhirepository = yangzhirepository;
        }

        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<APIResult> Handle(YangZhiQueryRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.code = (int)MSEnums.查询成功;
            result.message = MSEnums.查询成功.ToString();

            try
            {
                var list = yangzhirepository.GetAll();
                result.data = list.ToList();
                return Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
